import {formatGMTDate,toPercent,arrayToObject} from '../../../../assets/js/util.js'
import echarts from 'echarts'
export default {
    data() {
        return {
            // 默认参数 和 URL
            SRC: '',
            DP: {
                p: '',
                f: ''
            },
            // title
            title: "平台对帐查询",
            xlsxTitle:'',
            /* 的宽*/
            pageWidth: '100%',
            /*当前页显示数量*/
            pageSize: 10,
            /*每页显示的数量*/
            pageSizes: [10, 20, 50, 100],
            /*dataTotal表数量*/
            dataTotal: 0,
            /*分页器*/
            currentPage: 1,
            // 选择的时间
            date:"",
            // 渠道数组
            plats: [],
            // 渠道数组
            channels: [],
            // 服务器数组
            servers: [],
            // 默认的一些时间范围
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近15天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            postObj: {
                dstart : '',
                dend : ''
            },
            activeName: '1',
            //定义汇总数据的表头和数据
            reconciliationBusinessAllTabelHead:[
                {prop:"addcash",label:"总计"},
                {prop:"iosAddcash",label:"苹果平台"},
                {prop:"androidAddcash",label:"安卓平台"},
                {prop:"webAddcash",label:"WEB直充"},
                {prop:"odernum",label:"总计"},
                {prop:"iosAddcash",label:"苹果平台"},
                {prop:"androidOdernum",label:"安卓平台"},
                {prop:"webOdernum",label:"WEB直充"}


            ],
            reconciliationBusinessAllData:[],
            //定义详细数据的表头和数据
            reconciliationBusinessDetailTabelHead:[
                {prop:"day",label:"日期"},
                {prop:"addcash",label:"总计"},
                {prop:"iosAddcash",label:"苹果平台"},
                {prop:"androidAddcash",label:"安卓平台"},
                {prop:"webAddcash",label:"WEB直充"},
                {prop:"odernum",label:"总计"},
                {prop:"iosAddcash",label:"苹果平台"},
                {prop:"androidOdernum",label:"安卓平台"},
                {prop:"webOdernum",label:"WEB直充"}
            ],
            reconciliationBusinessDetailData:[],
            reconciliationBusinessDetailDataAll:[]
        }
    },
    computed:{
        // xlsx(){
        //     return this.title+'.xlsx';
        // }
    },
    methods: {
        chartsWidth (el){
            if(document.getElementById(el)!==null){
                document.getElementById(el).style.width = window.innerWidth-261+"px";
            }
        },
        //初始化
        _init() {
            window.addEventListener('resize', function() {
                /*修改表格的宽度*/
                this.realTimeServiceTableWidth = document.body.clientWidth-240+"px";
                this.realTimeServiceContent = document.body.clientWidth-220+"px";
            }.bind(this))
        },
        // 通用 成功 与 失败
        successFun(data) {
            this.$message({
                message: data,
                type: 'success'
            });
        },
        errorFun(data) {
            this.$message.error(data);
        },
        // 选择游戏的平台
        handleSelect(key, keyPath) {
            if (key === '4') {
                this.$refs.advance.filterShow = true;
            } else {
                this.postObj['platform'] = key;
                this.postObj['server'] = '0';
                this.postObj['channel'] = '0';
            }
        },
        // 改变时间
        dateChange(val) {
            if (val === undefined || val ==='') {
                this.errorFun('请选择查看时间！')
            }else{
                var t = val.split(' - ')
                this.postObj.dstart = t[0];
                this.postObj.dend = t[1];
                this.getData(this.postObj);
            }
        },
        // 获取数据
        getData(){
            var that = this;
            /*dstart : '',
                dend : ''*/
            this.$http.jsonp(`${that.SRC}data/get.do?p=${that.DP.p}&f=${that.DP.f}&a=search`, {
                    params: {'ps':`dstart=${that.postObj.dstart}&dend=${that.postObj.dend}`}
                }).then(function(res){
                var data =  JSON.parse(JSON.parse(res.body));
                if(parseInt(data.res) === 0){
                        this.reconciliationBusinessAllData =data.dataList1;
                        this.reconciliationBusinessDetailDataAll = data.dataList2;
                }else{
                    this.getErrorMsg(Number(data.res))
                }
               this.dataTotal = this.reconciliationBusinessDetailDataAll.length;
                this.reconciliationBusinessDetailData = this.reconciliationBusinessDetailDataAll.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
            })
        },
        // 表格下载
        excel(tabelHead,data,val) {
            this.xlsxTitle = val+"-"+this.postObj.dstart+"到"+this.postObj.dend;
            this.downloadExl(tabelHead,data,this.xlsxTitle,val);
        },
        /*分页器*/
        handleSizeChange(val) {
            this.pageSize = val;
            this.reconciliationBusinessDetailData = this.reconciliationBusinessDetailDataAll.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.reconciliationBusinessDetailData = this.reconciliationBusinessDetailDataAll.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
        },
    },
    mounted() {
        // 初始化URL
        this.SRC = this.$store.getters.src;
        this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
        this.DP.f = localStorage.getItem('ZULONGBIPAGEID');

        this.date = [new Date(new Date().getTime() - 8*86400000),new Date(new Date().getTime() - 86400000)];
        this.postObj.dstart = formatGMTDate(new Date(new Date().getTime() - 8*86400000), true);
        this.postObj.dend = formatGMTDate(new Date(new Date().getTime() - 86400000), true);
        this._init();

        //请求获取页面数据
        this.getData(this.postObj);
    }
}